// File: readXML.js

// Start function when DOM has completely loaded 
	//Variable to support handle action.
var gIsOnStep1 = new Boolean(false) ;
var gIsOnStep2 = new Boolean(false) ;
var gIsOnStep3 = new Boolean(false) ;
var gIsOnMain = new Boolean(false);
var gIsOnSessionTime = new Boolean(false);

var gIsSendingEmail = new Boolean(false);

var gSessionTimePerRow = 3; //Number of session time on a row.

var gTempObject1;
var gTempObject2;
var gTempObject3;

var CurrentStep;
var gShowType = '';
var Step1HTML = '';
var TimeOut = 1500;
var gTimeOutToClose = 500;
var gLang = 1; //Page language.
var gFadeInTime = 100;

var gUrlPrintSessionTime = '';
var gRequestSessionTimeParam = '';

//Ngon ngu hien thi tren session time menu
var gLang_1 = new Array('Xem Tất Cả','Theo Tựa Phim','Theo Rạp','Theo Ngày','Chọn Phim','Chọn Rạp','Chọn Ngày','Chọn Lịch Chiếu','Xin lỗi bạn, lịch chiếu đang được cập nhật','Xem Thêm','In','Gởi Vô Email', 'Click vào lịch chiếu để mua vé online');
var gLang_2 = new Array('View All','By Movies','By Cinema','By Date','Select Movie','Select Cinema','Select Date','Select Session','Sorry, session times data is being updated','View More','Print','Send To Mail', 'Click Session time to buy tickets');
var gCurrentLang = new Array();
var gLangAlias = "";

var isCloseSubSessionMenu = false;
var closeTM = 0;
function addslashes (str) {
    // Escapes single quote, double quotes and backslash characters in a string with backslashes  
    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\u0000/g, "\\0");
}


$(window).resize(function(){
	customizeMenu();
});


function customizeMenu(){
	var left = $("#SessionTime").offset().left;
	var top = $("#SessionTime").offset().top;
	$("#divSessionTime").css('left',left - 110);
	$("#divSessionTime").css('top',top + 5);
}

function simulatorDown(height){
	//$("#sessionTimeSimulator").css('height',height);
	$("#sessionTimeSimulator").slideDown();
}
function simulatorUp(){
	
	$("#sessionTimeSimulator").slideUp();
}
$(document).ready(function(){ 
	customizeMenu();
	
	//Get page language;
	if(ddl_session_time_lang)
		gLang = ddl_session_time_lang;
	/*else if($.url.param("visLang")){
		gLang = $.url.param("visLang");
		if (gLang != 1 && gLang !=2) 
			gLang=1;
	}*/
	
	//Get language alias
	if(gLang == 1)//Tiếng Việg
	{
	    gLangAlias = 'vn';
	}
	else //English
	{
	    gLangAlias = 'en';
	}
	
	$('select').css({'z-index':'1'});
	
	
	if (gLang == 1)
		gCurrentLang = gLang_1;
	else
		gCurrentLang = gLang_2;
	
	//set page language (just for session time menu)
	$('#Movie').html(gCurrentLang[1]);
	$('#Cinema').html(gCurrentLang[2]);
	$('#Date').html(gCurrentLang[3]);
	$('#see_all').html(gCurrentLang[0]);
	$('#session_time_title').html(gCurrentLang[7]);
	$('#st_send_mail').attr({'title':gCurrentLang[11]});
	$('#st_print_btn').attr({'title':gCurrentLang[10]});
	
	//Hide title of steps
	$('#steps_title').hide();
	
	
	
//HANDLE EVENT ===========================
	//Handle rootVoice navigator (The main navigator.)
	$('.rootVoice').mouseover(function(){
		if(!$(this).is('#SessionTime')){
			$('#SessionTime').removeClass('active');
			clearScreen();
			closeup();
		}else{
			$('#SessionTime').addClass('active');	
		}
		resetParam();
	});
	
	//Handle #SessionTime event (an item of main menu)	
	
	$('#SessionTime').mouseover(function(){		
		gIsOnSessionTime = true;	
		$('#divSessionTime').slideDown();
		$("#main_sub_nav").find('a').each(function(){
		    if(!$(this).is('#st_up_btn')){
		       /* $(this).attr({'class':'selected'});		*/
			   isCloseSubSessionMenu = false;  
			   clearTimeout(closeTM);
			   simulatorDown(32);
		    }		    
		});
	});	
	
	$('#SessionTime').mouseleave(function(){		
		gIsOnSessionTime = false;
		$("#main_sub_nav").find('a').each(function(){
		    if(!$(this).is('#st_up_btn')){
		       /* $(this).attr({'class':'unselected'});	*/
			   isCloseSubSessionMenu = true;
			   //closeTM = setTimeout(closeSTN,100);        
		    }		    
		});
		if(gTempObject3)
			$(gTempObject3).attr({'class':'selected'});
	});
	
	//Handle #divSessionTime event
	$('#divSessionTime').mouseleave(function(){
		isCloseSubSessionMenu = true;
		closeTM = setTimeout(closeSTN,100);
		gIsOnMain = false;
	});
	
	$('#divSessionTime').mouseover(function(){
		isCloseSubSessionMenu = false;
		clearTimeout(closeTM);
		gIsOnMain = true;		
		gIsSendingEmail = false;
	});		
	
	//Handle #Movie event.
	$("#Movie").click(function(){
		gTempObject3 = this;
		clearScreen();
		
		//$('select').hide();//to solve problem from IE. Desc: The div will under the selection
		$('#_ctl0_ContentPlaceHolder1_drpGenres').hide();//to solve problem from IE. Desc: The div will under the selection
		
		
		gShowType = 'Movie';
		gIsOnStep1 = true;
		CurrentStep = 1;
		var step = 1;		
		
		$('#steps_title').show();
		showMovieList(step,'');	
		$('#step_1_title').html(gCurrentLang[4]);
		$('#step_2_title').html(gCurrentLang[5]);
		$('#step_3_title').html(gCurrentLang[7]);
		$('#step3_session_title').html(gCurrentLang[gCurrentLang.length - 1]);
		
		$("#Movie,#Cinema,#Date").attr({'class':'unselected'});
		$(this).attr('class','selected');


	    //Call google tracking
	    urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_"+gShowType);
	    //--------------------
		if (typeof document.body.style.maxHeight == "undefined" || (document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)){
			
			
		}else{
			 $('#divSessionTime').jqmShow();
		}
		
	   
		
	});
	
	//Handle #Cinema click event.
	$("#Cinema").click(function(){
		if (typeof document.body.style.maxHeight == "undefined" || (document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)){
			
			
		}else{
			 $('#divSessionTime').jqmShow();
		}
		gTempObject3 = this;
		clearScreen();	
		//$('select').hide();//to solve problem from IE. Desc: The div will under the selection
		$('#_ctl0_ContentPlaceHolder1_drpGenres').hide();//to solve problem from IE. Desc: The div will under the selection
		gShowType = 'Cinema';
		gIsOnStep1 = true;
		CurrentStep = 1;
		var step = 1;
		
		$('#steps_title').show();
		showCinemaList(step,'');
		
		$('#step_1_title').html(gCurrentLang[5]);
		$('#step_2_title').html(gCurrentLang[4]);
		$('#step_3_title').html(gCurrentLang[7]);
		$('#step3_session_title').html(gCurrentLang[gCurrentLang.length - 1]);
		
		$("#Movie,#Cinema,#Date").attr({'class':'unselected'});
		$(this).attr('class','selected');

	    //Call google tracking
	    urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_"+gShowType);
	    //--------------------
	});
	
	//Handle #Date click event.
	$("#Date").click(function(){
	    if (typeof document.body.style.maxHeight == "undefined" || (document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)){
			
			
		}else{
			 $('#divSessionTime').jqmShow();
		}
		gTempObject3 = this;
		clearScreen();
		//$('select').hide();//to solve problem from IE. Desc: The div will under the selection
		$('#_ctl0_ContentPlaceHolder1_drpGenres').hide();//to solve problem from IE. Desc: The div will under the selection
		
		gShowType = 'Date';
		gIsOnStep1 = true;
		CurrentStep = 1;
		var step = 1;
		
		$('#steps_title').show();
		showDateList();
		
		$('#step_1_title').html(gCurrentLang[6]);
		$('#step_2_title').html(gCurrentLang[5]);
		$('#step_3_title').html(gCurrentLang[7]);
		$('#step3_session_title').html(gCurrentLang[gCurrentLang.length - 1]);
		
		$("#Movie,#Cinema,#Date").attr({'class':'unselected'});
		$(this).attr('class','selected');

	    //Call google tracking
	    urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_"+gShowType);
	    //--------------------
	});
	
	//Handle #print_btn event
	$('#st_print_btn').click(function(){
		showPopUp(gUrlPrintSessionTime,600,500);	
					 
	    //Call google tracking
	    if(gShowType == "Movie"){
	        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Movie_Cinema_SesstionTime_Print");
	    }else if(gShowType == "Cinema"){
	        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Cinema_Movie_SesstionTime_Print");	    
	    }else if(gShowType == "Date"){
	        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Date_Cinema_SesstionTime_Print");	        
	    }
	    //--------------------
	});
	
	//Handle #st_send_mail event
	$('#st_send_mail').click(function(){
	    
		/*gIsSendingEmail = true;
		
		openPopupSTSendMail(gLang);
		
	    //Call google tracking
	    if(gShowType == "Movie"){
	        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Movie_Cinema_SesstionTimeGroupByDate_SendMail");
	    }else if(gShowType == "Cinema"){
	        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Cinema_Movie_SesstionTimeGroupByDate_SendMail");	    
	    }else if(gShowType == "Date"){
	        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Date_Cinema_SesstionTimeGroupByMovie_SendMail");      
	    }
	    //--------------------
		*/
	});
	
	//Handle #st_up_btn event
	//When user click close button -> close session time navigator.
	$('#st_up_btn').click(function(){		
		closeSTN();
	});	
	
	//When user click any where out of STN and not doing send session email, Close STN.
	$('*').click(function(){
	    //neu con chuot nam ngoai main, va dang co step duoc goi thi dong lai.
	    //alert(gIsOnMain + ' ' + gIsOnStep1 + ' ' +gIsOnStep2 + ' ' +gIsOnStep3);		
	    if (!gIsOnSessionTime &&!gIsOnMain && !gIsSendingEmail){
		    closeSTN()
	    }
	});
	

	
});//END HANDLE EVENT.

function share_session_time_by_email(){
	gIsSendingEmail = true;
		
	openPopupSTSendMail(gLang);
	
	//Call google tracking
	if(gShowType == "Movie"){
		urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Movie_Cinema_SesstionTimeGroupByDate_SendMail");
	}else if(gShowType == "Cinema"){
		urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Cinema_Movie_SesstionTimeGroupByDate_SendMail");	    
	}else if(gShowType == "Date"){
		urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Date_Cinema_SesstionTimeGroupByMovie_SendMail");      
	}

}

//Control closing up session time navigator.
//Close STN and reset parameter.
function closeSTN(){
    //Close navigator
	if(isCloseSubSessionMenu){
		clearScreen();
		closeup();
		resetParam();
		simulatorUp();
		$('#divSessionTime').jqmHide();
	}
    
    
}
function resetParam(){
     //reset parameter.
    gIsOnStep1 = false;
	gIsOnStep2 = false;
	gIsOnStep3 = false;	
    gIsOnMain = false;
    gIsSendingEmail = false;
   
}
function closeup(){
	$('#steps_title').hide();
	$('#divSessionTime').slideUp();
	$('#SessionTime').removeClass('active');
	$('#_ctl0_ContentPlaceHolder1_drpGenres').show();
	gTempObject3 = "undefined";
	
}

function clearScreen(){
	gIsOnStep1 = false;
	gIsOnStep2 = false;
	gIsOnStep3 = false;
	$('#step1,#step2,#step3,#step4').fadeOut(0);	
}

/*Showing steps scenario overview:
    #: step1 -> step2 -> step3 -> final
    Movie -> Cinema -> Date -> Time
    Cinema -> Movie -> Date -> Time
    Date -> Cinema -> Movie -> Time
*/

//Control show step 2
function showStep2(filter1,object)
{
	//If step1 close then do nothing.
	if (!gIsOnStep1) return;
	
	var step = 2;
	gIsOnStep2 = true;
	if (gShowType == 'Movie'){
		showCinemaList(step,filter1);
	}
	else if (gShowType == 'Cinema'){
		showMovieList(step,filter1);
	}
	else if (gShowType == 'Date'){
		showCinemaList(step,filter1);
	}
	$('#step3').fadeOut(0);	
	
	$(gTempObject1).removeClass('selected');
	//alert($('step_1_content').find('.selected'));
	$(object).addClass('selected');
	
	gTempObject1=object;

    //Call google tracking
    if(gShowType == "Movie"){
        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Movie_Cinema");
    }else if(gShowType == "Cinema"){
        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Cinema_Movie");	    
    }else if(gShowType == "Date"){
        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Date_Cinema");	        
    }
    //--------------------

}
//Control show step 3
function showStep3(filter1,filter2,object)
{
	gIsOnStep3 = true;
	
	if (gShowType == 'Movie' || gShowType == 'Cinema'){
		showTimeList1(filter1,filter2);	
	}else if (gShowType == 'Date'){
		showTimeList2(filter1,filter2);	
	}
	
	$(gTempObject2).removeClass('selected');
	//alert($('step_1_content').find('.selected'));
	$(object).addClass('selected');
	
	gTempObject2 = object;
	    
    //Call google tracking
    if(gShowType == "Movie"){
        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Movie_Cinema_SesstionTimeGroupByDate");
    }else if(gShowType == "Cinema"){
        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Cinema_Movie_SesstionTimeGroupByDate");	    
    }else if(gShowType == "Date"){
        urchinTracker(gLangAlias +"_"+"SessionTimeNavigator"+"_Date_Cinema_SesstionTimeGroupByMovie");    
    }
    //--------------------

}

function handleHideStep1()
{
	if ((gIsOnStep2 == false) && (gIsOnStep3 == false)){
		gIsOnStep1 = false;
		$("#step1").fadeOut();		
	}		
}

//Get xmlpath of movie list.
function getXmlPath(step,list_type,filter1,filter2)
{
	if(!step) step = 1;
	//alert(list_type+''+filter1+''+filter2+''+gShowType);
	XMLpath = '';
	if (list_type == 'Movie'){
		if (step == 1){
			//XMLpath = "/megastarXMLData.aspx?RequestType=GetMovieListByMode&&visMode=NowShowing&&visLang=" + gLang;
			XMLpath = "/megastarXMLData.aspx?RequestType=GetMoviesHasSession&&visLang=" + gLang;
		}else{ //step 2. Get movie list filted by cinema id
			XMLpath ="/megastarXMLData.aspx?RequestType=GetMovieListByCinemaID&&CinemaID=" + filter1 + "&&visLang=" + gLang;
		}		
	}else if (list_type == 'Cinema'){
		if (step == 1){
			XMLpath ="/megastarXMLData.aspx?RequestType=GetCinemaList&&visLang=" + gLang;
		}else if (step == 2 && gShowType == 'Date'){ 
			XMLpath ="/megastarXMLData.aspx?RequestType=GetCinemaList&&visLang=" + gLang;
		}else{//step 2
			XMLpath ="/megastarXMLData.aspx?RequestType=GetCinemaList&&MovieName=" + filter1 + "&&visLang=" + gLang;
		}	
	}else if (list_type == 'Date'){
			XMLpath ="/megastarXMLData.aspx?RequestType=GetDateList&&visLang=" + gLang;
	}else if (list_type == 'Time'){//All in step 3
		if(gShowType == 'Date'){
			XMLpath = '/megastarXMLData.aspx?RequestType=GetSessionsByCinemaAndDate&&CinemaID=' + filter1 + '&&Date=' + filter2 + '&&visLang=' + gLang;			
		}else {//Normal
			XMLpath = '/megastarXMLData.aspx?RequestType=GetSessionTimes&&CinemaID='+ filter1 +'&&MovieName=' + filter2 + '&&Time=TodayAndTomorrow&&visLang=' + gLang;
			//XMLpath = '../megastarXMLData.aspx?RequestType=GetSessionTimes&&CinemaID=1006&&MovieName=Avatar&&Time=TodayAndTomorrow&&visLang=1';
		} 
	}
	
	return XMLpath;
}

//Show movie list
/*
	step: 1, 2. de xac dinh div hien thi movie se duoc de o cho nao.
	cinema_id: de xac dinh cach lay du lieu xml. -> co loc theo cinema ko hay lay toan bo.
*/
function showMovieList(step,filter)
{
	var XMLpath = getXmlPath(step,"Movie",filter);
	
	$.get(XMLpath,{},function(xml){
		// Build an HTML string
		myHTMLOutput = '';
		myHTMLOutput += '<ul id="ul_menu" class="ul_menu">';
		
		// Run the function for each movie tag in the XML file
		$('movie',xml).each(function(i) {
			var MovieId = $(this).find("MovieId").text();
			var MovieName = $(this).find("MovieName").text();
			var MovieNameShort = $(this).find("MovieNameShort").text();
			var ImageUrlSmall = $(this).find("ImageUrlSmall").text();
			var ImageUrlLarge = $(this).find("ImageUrlLarge").text();
			var MovieNameVar = addslashes($(this).find("MovieNameVar").text());
			var Trailer = $(this).find("Trailer").text();
			var MovieInfoUrl = $(this).find("MovieInfoUrl").text();
			var Award = $(this).find("Award").text();
			var ShortDesc = $(this).find("ShortDesc").text();
	        
			// Build row HTML data and store in string.
			if(gShowType == 'Cinema' ){ //go to step 3 and display showing time.
				myHTMLOutput += '<li id="' + MovieNameVar + '"><a onclick="showStep3(\'' + filter + '\',\'' + MovieNameVar + '\',this);" href="javascript: void(0);">' + MovieName + '</a></li>';
			}else if(gShowType == 'Movie' ){
				myHTMLOutput += '<li id="' + MovieId + '"><a onclick="showStep2(\'' + MovieNameVar + '\',this);" href="javascript: void(0);">'+ MovieName + '</a></li>';
			}
			
		});		
		myHTMLOutput += '</ul>';
		
		//Show data
		if (step == 1){
			$("#step_1_content").html(myHTMLOutput);
			$("#step1").fadeIn(gFadeInTime);
			$("#step4").fadeIn(gFadeInTime);
			$('#step_1_content').jScrollPane({'dragMaxHeight':80,'dragMinHeight':80});
		}else{
			$("#step_2_content").html(myHTMLOutput);
			$("#step2").fadeIn(gFadeInTime);	
			$('#step_2_content').jScrollPane({'dragMaxHeight':80,'dragMinHeight':80});			
		}
	},"xml");	
};

function showCinemaList(step,MovieName)
{
	
	var XMLpath = '';
	XMLpath = getXmlPath(step,"Cinema",MovieName);
	$.get(XMLpath,{},function(xml){
		// Build an HTML string
		myHTMLOutput = '';
		DataBody = '';
		myHTMLOutput += '<ul class="ul_menu">';
		
		// Run the function for each movie tag in the XML file
		$('Cinema',xml).each(function(i) {
			Cinema_strID = $(this).find("Cinema_strID").text();
			Cinema_strName = $(this).find("Cinema_strName").text();
			Cinema_strNameShort = $(this).find("Cinema_strNameShort").text();
			Cinema_strDisplayName = $(this).find("Cinema_strDisplayName").text();
			MovieNameVar = urlencode(MovieName);
			// Build row HTML data and store in string
			if(gShowType == 'Movie' || gShowType == 'Date' ){ //go to step 3
				DataBody += '<li id="' + Cinema_strID + '"><a onclick="showStep3(\'' + Cinema_strID + '\',\'' + MovieNameVar + '\',this);" href="javascript: void(0);">'+ Cinema_strDisplayName + '</a></li>';
			}else if(gShowType == 'Cinema' ){//go to step 2.
				DataBody += '<li id="' + Cinema_strID + '"><a onclick="showStep2(\'' + Cinema_strID + '\',this);" href="javascript: void(0);">'+ Cinema_strDisplayName + '</a></li>';
			}
		});
		
		if (!DataBody){	
			myHTMLOutput += '<span class="st_sorry">'+gCurrentLang[8] + '</span></ul>';
			gIsOnStep3 = false;
			$('#step3').fadeOut(0);
		}
		else {
			myHTMLOutput += DataBody + '</ul>';
		}
		
		//Show data
		if (step == 1){
			$("#step_1_content").html(myHTMLOutput);
			$("#step1").fadeIn(gFadeInTime);
			$("#step4").fadeIn(gFadeInTime);
			$('#step_1_content').jScrollPane({'dragMaxHeight':80,'dragMinHeight':80});
		}else{
			$("#step_2_content").html(myHTMLOutput);
			$("#step2").fadeIn(gFadeInTime);
			$('#step_2_content').jScrollPane({'dragMaxHeight':80,'dragMinHeight':80});
		}
	});
};


function showDateList()
{
	var getXmlType = 'Date';
	var step = 1;
	var XMLpath = '';
	XMLpath = getXmlPath(step,getXmlType);		
	$.get(XMLpath,{},function(xml){
		// Build an HTML string
		myHTMLOutput = '';
		DataBody = '';
		myHTMLOutput += '<ul>';
		
		// Run the function for each movie tag in the XML file
		$('date',xml).each(function(i) {
			date_name = $(this).text();
			date = $(this).attr("value");
			
			// Build row HTML data and store in string
			DataBody += '<li id="' + date_name + '"><a onclick="showStep2(\''+ date +'\',this);" href="javascript: void(0);">'+ date_name + '</a></li>';
		});
		
		myHTMLOutput += DataBody + '</ul>';
		
		//Show data
		$("#step_1_content").html(myHTMLOutput);
		$("#step1").fadeIn(gFadeInTime);
		$("#step4").fadeIn(gFadeInTime);
	});
};


function showTimeList1(filter1,filter2)
{	
	gIsOnStep3 = true;
	var XMLpath = '';
	XMLpath = getXmlPath(3,"Time",filter1,filter2);
	
	$.get(XMLpath,{},function(xml){
		// Build an HTML string
		var myHTMLOutput = "";
		var DataBody = "";
		var Time =  "";
		myHTMLOutput +=  "";
		
		// Run the function for each movie tag in the XML file
		var count = 0;
		
		$(xml).find('[name]').each(function() {
			var date_name = $(this).attr('name');

			Time = "";
			count = 0;
			DataBody += "<div class=\"clear\"></div>"; 
			DataBody += "<p><h3 class=\"date\">" + date_name + "</h3></p>";
			$(this).find('time').each(function(){
				var ticket_url = $(this).find("ticket_url").text();
				var value = $(this).find("value").text();
				
				var id = $(this).find("id").text();
				var date = $(this).find("date").text();
							
				if(count % gSessionTimePerRow == 0 && count > 0){					
					Time += "<div class=\"clear\"></div>"; 
				}
				
				Time += "<span class=step_3_content_chid_span>" + value + "</span>";
				count ++;
				
			});			
			
			// Build row HTML data and store in string
			DataBody += Time;
			
			Time = "";
		});
		
		if (!DataBody)	{			
			//myHTMLOutput += "<span class=st_sorry>"+gCurrentLang[8]+"</span></p>";	
			myHTMLOutput += "<span class=st_sorry>"+gCurrentLang[8]+"</span>";	
		}else {			
			//myHTMLOutput += DataBody + "</p><p></p>";			
			myHTMLOutput += DataBody;			
		}

		
		
		
		//Show data
		$("#step_3_content_child").html(myHTMLOutput);
		$("#step3").fadeIn(gFadeInTime);
		$('#step_3_content_child').jScrollPane({'dragMaxHeight':80,'dragMinHeight':80});
		
		//Create link to print session time.
		gRequestSessionTimeParam = XMLpath.replace('/megastarXMLData.aspx?','');
		gUrlPrintSessionTime = XMLpath.replace('megastarXMLData','msPrintSessionTime');
	});
		
};

function showTimeList2(filter1,filter2)
{
	gIsOnStep3 = true;
	var XMLpath = '';
	XMLpath = getXmlPath(3,"Time",filter1,filter2);
	
	$.get(XMLpath,{},function(xml){
		// Build an HTML string
		myHTMLOutput = '';
		DataBody = '';
		Time = '';
		myHTMLOutput += '';
		
		// Run the function for each movie tag in the XML file
		
		$('movie',xml).each(function(i) {
			var movie_name = $(this).find("name").text();
			
			DataBody += '<p><h3 class="date">' + movie_name + '</h3></p>';
			Time = '';
			var count = 0;
			$('time',this).each(function(i){
				var ticket_url = $(this).find("ticket_url").text();
				var value = $(this).find("value").text();
				//value = value.replace("\"","\\\"");
				
				var id = $(this).find("id").text();
				var date = $(this).find("date").text();	
				
				if(count % gSessionTimePerRow == 0 && count > 0){
					Time += '<p><span class="step_3_content_chid_span">' + value + '</span>'; 
				}else{
					Time += '<span class="step_3_content_chid_span">' + value + '</span>';
				}
				
				count ++;
				
			});
			
			// Build row HTML data and store in string
			DataBody += Time;
		});
		if (!DataBody)
			myHTMLOutput += '<span class="st_sorry">'+gCurrentLang[8] + '</span></p>';	
		else 
			myHTMLOutput += DataBody + '</p><p></p>';
		
		//Show data
		$("#step_3_content_child").html(myHTMLOutput);
		$("#step3").fadeIn(gFadeInTime);
		$('#step_3_content_child').jScrollPane({'dragMaxHeight':80});
		
		//Create link to print session time.
		gRequestSessionTimeParam = XMLpath.replace('/megastarXMLData.aspx?','');
		gUrlPrintSessionTime = XMLpath.replace('megastarXMLData','msPrintSessionTime');
	});
	
};



//Create window popup.
function showPopUp(url,height,width) {
	if(!height) height = 400;
	if(!width) width = 300;
	
	var newwindow = window.open(url,'mywindow','height='+height+', width='+width+', top=70px, left=70px, menubar=no, status=yes, location=yes, toolbar=no, scrollbars=yes');
	if (window.focus) {newwindow.focus()}
		return false;
}



////CONTROL SEND SESSTION TIME INTO MAIL
//Open Getting user info form.
function openPopupSTSendMail(visLang){   
    gIsSendingEmail = true;
    var sBtnSumitName = "";
    var sBtnSendAnotherFriend = "";
    if(visLang == 1)// Tiếng Việt
    {
        sBtnSumitName = 'GỬI';
        sBtnSendAnotherFriend = 'GỬI CHO CÁC BẠN KHÁC';
    }else // English
    {
        sBtnSumitName = 'Send';
        sBtnSendAnotherFriend = 'Send to more friends';
    }
    
    jQuery.ajax({
        type: "GET",
		url: "/msSTSendMail.aspx?visLang=" + visLang,
		data: "",
		dataType: "html",
		success: function(html){		    			
			$.prompt(html,{
		        submit: sendSessionTimeToEmail, 
		        buttons: {Send:true},
		        loaded:function(){
		            $("#jqi").css("width","550px");
		            $("#jqi_state0_buttonSend").html(sBtnSumitName);
		        }
		    });
			return false;
		}
    });
	return false;
}


function sendSessionTimeToEmail()
{
    if(gLang == "1") //Tiếng Việt (visLang == "1")
    {
        lblHThankYou = "Cám ơn, một email đã được gửi tới cho bạn của bạn!";
        lblHErrNameEmpty = "Vui lòng nhập tên của bạn!";
        lblHErrEmailEmpty = "Vui lòng nhập email của bạn!";
        lblHErrEmailValid = "Địa chỉ email không hợp lệ. Vui lòng nhập lại!";
        lblHErrFriendNameEmpty = "Vui lòng nhập tên của người nhận!";
        lblHErrFriendEmailEmpty = "Vui lòng nhập địa chỉ email của người nhận!";
        lblHErrSubjectEmpty = "Vui lòng điền tiêu đề thông điệp!";
    }
     else //English
    {
        lblHThankYou = "Thank you, an email has been sent to your friend!";
        lblHErrNameEmpty = "Please enter your name!";
        lblHErrEmailEmpty = "Please enter your email address!";
        lblHErrEmailValid = "Invalid email. Please enter your email again!";
        lblHErrFriendNameEmpty = "Please enter your friend’s name!";
        lblHErrFriendEmailEmpty = "Please enter your friend’s email address!";
        lblHErrSubjectEmpty = "Please enter message subject!";
    }
   
    //Check client name is empty
    if($("#txtCName").val() == ""){
        alert(lblHErrNameEmpty);
        $("#txtCName").focus();
        return false;
    }
    
    //Check client email is empty
    if($("#txtCEmail").val() == ""){
        alert(lblHErrEmailEmpty);
        $("#txtCEmail").focus();
        return false;
    }
    
    //Validate client email.
    if(isValidEmail($("#txtCEmail").val()) == false){
        alert(lblHErrEmailValid);
        $("#txtCEmail").focus();
        return false;
    }

    //Check friend name is empty
    if($("#txtFName").val() == ""){
        alert(lblHErrFriendNameEmpty);
        $("#txtFName").focus();
        return false;
    }    
    
    //Check friend Email is Empty
    if($("#txtFEmail").val() == ""){
        alert(lblHErrFriendEmailEmpty);
        $("#txtFEmail").focus();
        return false;
    }
    
    
    //Validate friend email
    if(isValidEmail($("#txtFEmail").val()) == false){
        alert(lblHErrEmailValid);
        $("#txtFEmail").focus();
        return false;
    }
    
    //Validate more friend
    
	var i = 0;
	for(i = 2; i<5; i++){
		if($("#txtFName_"+i).val() != "" || $("#txtFEmail_"+i).val() != ""){
			if ($("#txtFName_"+i).val() == ""){
				alert(lblHErrFriendNameEmpty);
				$("#txtFName_"+i).focus();
				return false;
			}            
			
			if($("#txtFEmail_"+i).val() == ""){
				alert(lblHErrFriendEmailEmpty);
				$("#txtFEmail_"+i).focus();
				return false;
			}
			
			if(isValidEmail($("#txtFEmail_"+i).val()) == false){
				alert(lblHErrEmailValid);
				$("#txtFEmail_"+i).focus();
				return false;
			}
		}    
	}
    
    var sAddMoreFriend = '';
    
	var i;
	for (i = 2; i<5 ; i++){
		if($("#txtFEmail_" + i).val() != ""){
			sAddMoreFriend += "&&FName_" + i + "=" + $("#txtFName_"+i).val();
			sAddMoreFriend += "&&FEmail_" + i + "=" + $("#txtFEmail_"+i).val();
		}
	}
    

    var dataString =  "CName=" + $("#txtCName").val() ;
    dataString += "&&CEmail=" + $("#txtCEmail").val() ;
    dataString += "&&FName=" + $("#txtFName").val() ;
    dataString += "&&FEmail=" + $("#txtFEmail").val() ;
    dataString += sAddMoreFriend ;
    //dataString += "&&Subject=" + $("#txtSubject").val() 
    //dataString += "&&Message=" + $("#txtMessage").val()
    dataString += "&&" + gRequestSessionTimeParam;//Add parameter to get session time.
    //dataString = urlencode(addslashes(dataString));
    jQuery.ajax({
        type: "POST",
		url: "/msSTSendMailProcess.aspx",
		data: dataString,
		dataType: "html",
		success: function(html)
		{
		    $.prompt.close();
		    alert(lblHThankYou);
		}
    });
    
    return false;
}

